/*
 * Copyright 2003-2005 (c) Live Media Pty Ltd. <argot@einet.com.au> 
 *
 * This software is licensed under the Argot Public License 
 * which may be found in the file LICENSE distributed 
 * with this software.
 *
 * More information about this license can be found at
 * http://www.einet.com.au/License
 * 
 * The Developer of this software is Live Media Pty Ltd,
 * PO Box 4591, Melbourne 3001, Australia.  The license is subject 
 * to the law of Victoria, Australia, and subject to exclusive 
 * jurisdiction of the Victorian courts.
 */

#include "../src/Types.h"
#include "../src/dictionary/DictionaryTypes.h"
#include "../src/dictionary/Dictionary.h"
#include "../src/TypeBindCommon.h"

#include <stdio.h>

#ifdef _PSP

#include <pspkernel.h>
#include <pspdebug.h>

PSP_MODULE_INFO("Argot TypeTest", 0, 1, 0);
PSP_MAIN_THREAD_ATTR(THREAD_ATTR_USER | THREAD_ATTR_VFPU);

#endif

static type_library system_library;

static reference_type_map core_map;

static type_map dictionary_map;

typedef struct file_data
{
	FILE * fd;
}
file_data;


int fileReader( type_input_stream * in, void * data, char * buffer, int size )
{
	file_data * fileData = (file_data *) data;

	return fread( buffer, 1, size, fileData->fd );	
}

int main (int argc, char **argv)
{
	file_data fileData;
	int rc;
	
	type_library_init( &system_library );

	rc = type_core_init( &system_library );
	if ( rc != TYPE_OK )
	{
		printf( "failed to init core\n");
		return -1;
	}
	
	rc = dictionary_types_init( &system_library );
	if ( rc != TYPE_OK )
	{
		printf( "failed to init dictionary\n" );
		return -1;
	}
	
	reference_type_map_init( &core_map, &system_library, NULL );
	type_map_core_init( &core_map );

#ifdef _PSP
	fileData.fd = fopen( "common.dictionary","r" );
#else
	fileData.fd = fopen( "C:\\project\\einet\\product\\c\\argot\\common.dictionary","r" );
#endif

	if ( fileData.fd == NULL )
	{
		printf( "failed to open common dictionary\n" );
		return -1;
	}
	
	type_map_init( &dictionary_map, &system_library );
	
	rc = read_dictionary( &system_library, fileReader, &fileData, &dictionary_map );
	if (rc != TYPE_OK )
	{
		printf( "failed to read meta.dictionary\n" );
		return -1;
	}
	
	rc = type_bind_common( &system_library );
	if ( rc != TYPE_OK )
	{
		printf( "failed to bind common types\n" );
	}
	
	printf( "read meta.dictionary\n" );
	return 0;
}

